package com.example.llollama.commponent;

import org.springframework.ai.document.Document;
import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Component;

import java.net.MalformedURLException;
import java.util.List;

/**
 * @Description: TODO
 * @author: lonely
 * @date: 2024年11月19日 22:51
 */
@Component
public class MyHtmlReader {
//    private final Resource resource;
//    MyHtmlReader(@Value("https://baike.baidu.com/item/%E5%91%A8%E6%9D%B0%E4%BC%A6/129156")
//                         Resource resource) {
//        this.resource = resource;
//    }


    public List<Document> loadText(String url) throws MalformedURLException {
        Resource resource = new UrlResource(url);
        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(resource);
        return tikaDocumentReader.read();
    }
}
